package com.upload.pic;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Bimp {
	public static int max = 0;
	public static int max2 = 0;
	public static boolean act_bool = true;
	public static List<Bitmap> bmp = new ArrayList<Bitmap>();
	public static List<Bitmap> bmp2 = new ArrayList<Bitmap>();

	// 图片sd地址 上传服务器时把图片调用下面方法压缩后 保存到临时文件夹 图片压缩后小于100KB，失真度不明显
	public static List<String> drr = new ArrayList<String>();
	public static List<String> drr2 = new ArrayList<String>();

	public static Bitmap revisionImageSize(String path) throws IOException {
		BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(path)));
		BitmapFactory.Options options = new BitmapFactory.Options();
		options.inJustDecodeBounds = true;
		BitmapFactory.decodeStream(in, null, options);
		in.close();
		int i = 0;
		Bitmap bitmap = null;
		while (true) {
			if ((options.outWidth >> i <= 1000) && (options.outHeight >> i <= 1000)) {
				int degree = UploadUtils.getExifOrientation(path);
				in = new BufferedInputStream(new FileInputStream(new File(path)));
				options.inSampleSize = (int) Math.pow(2.0D, i);
				options.inJustDecodeBounds = false;
				bitmap = BitmapFactory.decodeStream(in, null, options);
				if (degree != 0) {
					bitmap = UploadUtils.adjustPhotoRotation(bitmap, degree);
				}
				break;
			}
			i += 1;
		}
		return bitmap;
	}

	public static void removeBitmap(int position) {
		if (position <= max) {
			bmp.remove(position);
			drr.remove(position);
			max--;
		}
	}

	public static void removeBitmap2(int position) {
		if (position <= max2) {
			bmp2.remove(position);
			drr2.remove(position);
			max2--;
		}
	}

	public static void clearPics() {
		if (Bimp.bmp != null) {
			Bimp.bmp.clear();
		}
		if (Bimp.drr != null) {
			Bimp.drr.clear();
		}
		Bimp.max = 0;

		if (Bimp.bmp2 != null) {
			Bimp.bmp2.clear();
		}
		if (Bimp.drr2 != null) {
			Bimp.drr2.clear();
		}
		Bimp.max2 = 0;
		FileUtils.deleteDir();
	}
	public static void clearPics2() {

		if (Bimp.bmp2 != null) {
			Bimp.bmp2.clear();
		}
		if (Bimp.drr2 != null) {
			Bimp.drr2.clear();
		}
		Bimp.max2 = 0;
	}
}
